package com.aaa.mythread;

public class MyThread8DeadLock implements Runnable {
    // 对象里面默认包含有锁
    private static Object obj1 = new Object();//定义成静态变量，使线程可以共享实例
    private static Object obj2 = new Object();//定义成静态变量，使线程可以共享实例
    public int flage = 0;

    public  void aaa(){

    }


    public  void bbb(){

    }


    @Override
    public void run() {
        if(flage==0){
            System.out.println("aaa中flage的值是："+flage);
            synchronized (obj1){
                System.out.println("flage的值是:"+flage);
                //
                synchronized (obj2){
                    System.out.println("------");
                }

            }

        }
        if(flage==1){
            System.out.println("bbb中flage的值是："+flage);
            synchronized (obj2){
                System.out.println("----flage的值是:"+flage);
                //
                synchronized (obj1){
                    System.out.println("---******---");
                }

            }

        }
    }


    public static void main(String[] args) {
        MyThread8DeadLock myThread8DeadLock = new MyThread8DeadLock();
        MyThread8DeadLock myThread8DeadLock2 = new MyThread8DeadLock();
        myThread8DeadLock2.flage=1;
        Thread thread = new Thread(myThread8DeadLock);
        thread.start();
        Thread thread2 = new Thread(myThread8DeadLock2);
        thread2.start();


    }
}
